{include "header.tpl"}

{if $basket->totalProducts() == 0}

	<div style="text-align:center;">
		нет товаров
	</div>
	<script>
		$(function(){
			$('#basket dt').html('');
			$('#basket dd').html('корзина пуста');
			$('#cartremainder span:first-child').html(0);
			$('#cartremainder span:nth-child(2)').html(0);
		});
	</script>
	
{else}

<form id=oForm method=post>

<table width=100%>
	<col>
	<col style="font-weight:bold; white-space:nowrap;">
	<col style="text-align:center;">
	<col style="text-align:center;">
	<tr style="font-weight:bold; white-space:nowrap;">
		<td>
		</td>		
		<td width=100%>
			Наименование
		</td>
		<td>
			Цена, руб.&nbsp;&nbsp;&nbsp;
		</td>
		<td>
			Количество
		</td>
	</tr>
	
	{section name=product loop=$products}
		<tr>
			<td>
				<input type=checkbox name='order_{$smarty.section.product.index}' checked/>
			</td>
			<td>
				<input type=hidden name='productIds[]' value='{$products[product][0]->id()}' />
				<a href='product.php?productId={$products[product][0]->id()}'>
						{$products[product][0]->name()} {$products[product][3]->name()} {$products[product][0]->model()}
						
				{if $products[product][1]}
					 - {$products[product][1]->name()}
					</a>
					<input type=hidden name='optionIds[]' value='{$products[product][1]->id()}' />
				{else}
					</a>					
					<input type=hidden name='optionIds[]' value=0 />						
				{/if}
				
			</td>
			<td>
				{if $products[product][1]}
					{$products[product][1]->price()}
				{else}
					{$products[product][0]->price()}
				{/if}
			</td>
			<td>
				<input type=text name='amounts[]' value='{$products[product][2]}' size=3 maxlength=10 />
			</td>
		</tr>
	{/section}
	
</table>

</form>

<script lang=javascript>
var prodCount = {$basket->totalProducts()};
var prodSum = {$basket->totalSum()};
{literal}
	function recountBasket()
	{
		var form = document.getElementById('oForm');
		form.submit();
	}
	
	function proceed()
	{
		var el = document.createElement('INPUT');
		el.type = 'hidden';
		el.name = 'proceed';
		el.value = 1;

		var form = document.getElementById('oForm');		
		form.appendChild(el);
		form.submit();
	}
	
	$(function(){
		$('#basket dt').html(prodCount);
		$('#cartremainder span:first-child').html(prodCount);
		$('#cartremainder span:nth-child(2)').html(prodSum);
	});
{/literal}
</script>


<script>
</script>

<br>
<div style="text-align:right; font-weight:bold;">
	Всего: {$basket->totalSum()} руб.
	<br>
	<br>
	<button onclick="recountBasket()">Пересчитать</button>
</div>

<br>
<br>
<div style="text-align:center;">
	<button onclick="proceed()">Оформить заказ</button>
</div>

{/if}


{include "footer.tpl"}